package map;

import java.util.Collection;
import java.util.Hashtable;
import java.util.Set;

public class HashtableDemo {
	public static void main(String[] args) {
		//1.创建一个map
		Hashtable<String,Integer> scores = new Hashtable<>();
		//2.放入
		scores.put("建宇", 20);
		scores.put("世宇", 21);
		scores.put("智斌", 61);
		scores.put("乃生", 99);
		scores.put("乃生", 100);  // key不允许重复，如果key重复，value会覆盖已有value
		System.out.println(scores);
		//3.求条目数
		System.out.println(scores.size());
		//4.根据key替换value
		scores.replace("建宇", 101);
		System.out.println(scores);
		//5.根据key得到value
		System.out.println(scores.get("智斌"));
		//6.得到所有的key
		Set<String> keySet = scores.keySet();
		System.out.println(keySet);
		//7.得到所有的value
		Collection<Integer> values = scores.values();
		System.out.println(values);
		//8.判断是否包含key
		boolean containsKey = scores.containsKey("建宇");
		// 是否包含某个value
		boolean containsValue = scores.containsValue(20);
		// 根据key删除
		Integer remove = scores.remove("乃生");
		
		//8.
		System.out.println(scores.isEmpty());
		//9.
		scores.clear();
		System.out.println(scores);
	}
}
